package com.edu.controller;

import com.edu.bean.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
@Api(value = "用户接口")
public class UserController {

    @ApiOperation(value="查询单个用户",notes="根据用户id查询用户")
    @PostMapping(value = "/getUser")
    @ResponseBody
    public Object getUser(@ApiParam(name="userId",value="",required = true)  @RequestParam int userId){
        User user = new User(userId,"zhangsan","123456","男",25);
        return user;
    }

    @ApiOperation(value="查询所有用户")
    @GetMapping("getAll")
    @ResponseBody
    public Object getAll(){
        User user1 = new User(1,"zhangsan","123456","男",25);
        User user2 = new User(2,"lisi","123456","男",25);
        User user3 = new User(3,"shufen","123456","男",25);
        List<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        users.add(user3);
        return users;
    }

    @ApiOperation(value="添加用户")
    @PostMapping("/insertUser")
    @ResponseBody
    public Object insertUser(User user){
        System.out.println("添加了用户"+user);
        return "success";
    }


    @ApiOperation(value="删除用户")
    @PostMapping("/deleteUser")
    @ResponseBody
    public Object deleteUser(@ApiParam(value="用户id") @RequestParam int userId){
        System.out.println("删除了用户"+userId);
        return "success";
    }
}
